<?php
$title = '友链新增';
include 'header.php';
$pdo = null;
?>
  <link href="../assets/css/sweetalert2.min.css" rel="stylesheet" type="text/css">
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-xl-6 offset-xl-3">
                    <div class="card">
                        <div class="card-body">
                                 <form class="custom-validation" onsubmit="return addyou();">
                                <div class="mb-3"><label class="form-label">网站favicon链接：</label>
                                    <div><input type="text" id="favicon" class="form-control" value="" placeholder="网站favicon链接" required=""></div>
                                </div>
                                <div class="mb-3"><label class="form-label">网站名称：</label>
                                    <div><input type="text" id="name" class="form-control" value="" placeholder="请输入网站名称" required=""></div>
                                </div>
                                     <div class="mb-3"><label class="form-label">网站域名(不带http/https)：</label>
                                    <div><input type="text" id="url" class="form-control" value="" placeholder="请输入网站域名" required=""></div>
                                </div>
                                <div class="text-center ">
                                    <div class="d-grid mt-4"><button type="submit" id="submit" class="btn btn-info btn-black  waves-effect waves-light">添加友联 </button></div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div><!-- end col -->
            </div><!-- end row -->
        </div><!-- container-fluid -->
    </div><!-- End Page-content -->
    <footer class="footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">
                    <script>
                        document.write(new Date().getFullYear())
                    </script>(c) Cloud.
                </div>
                <div class="col-sm-6">
                    <div class="text-sm-end d-none d-sm-block">Crafted with <i class="mdi mdi-heart text-danger"></i>By <a href="https://www.9gyun.cn">云风轻产品授权中心</a></div>
                </div>
            </div>
        </div>
    </footer>
</div><!-- end main content-->
<!--End 页面主要内容-->
<?php include("footer.php"); ?>
<script src="../assets/js/sweetalert2.min.js"></script>
<script language="JavaScript">
    function addyou() {
        var favicon = $("#favicon").val();
        var name = $("#name").val();
        var url = $("#url").val();
        if (!favicon || !name || !url) {
            return false;
        } else {
            $.ajax({
                type: "POST",
                url: "set.php?act=addyou",
                data: {
                   favicon:favicon,
                   name:name,
                   url:url
                },
                dataType: "json",
                success: function(data) {
                    if (data.state == 1) {
                        Swal.fire({
                            title: '添加成功!',
                            text: "添加成功,是否跳转到后台?",
                            icon: 'success',
                            showCancelButton: true,
                            confirmButtonText: '跳转至列表!',
                            cancelButtonText: '继续添加!',
                            confirmButtonClass: 'btn btn-success mt-2',
                            cancelButtonClass: 'btn btn-info ms-2 mt-2',
                            buttonsStyling: false
                        }).then(function(result) {
                            if (result.value) {
                                setTimeout(function() {
                                    window.location.href = 'youlist.php';
                                }, 1000);
                            } else if (result.dismiss === Swal.DismissReason.cancel) {
                                return false;
                            }
                        });

                    } else {
                        Swal.fire({
                        title: '添加失败!',
                        text: '未知错误',
                        icon: 'error',
                        confirmButtonText: '重新尝试!',
                        confirmButtonClass: 'btn btn-danger mt-2',
                    });
                    }
                }
            });
        }
        return false;
    }
</script>
</body>

</html>